package com.gg.ggw.controller;

import com.gg.ggw.model.GgArticle;
import com.gg.ggw.model.GgUser;
import com.gg.ggw.repository.UserRepository;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2016/12/5.
 */
@Controller
@RequestMapping(value = "test")
public class TestController {
    private Logger logger = org.apache.log4j.Logger.getLogger(TestController.class);

    @Autowired
    private UserRepository userRepository;

    @RequestMapping(value = "testhtml")
    public String testhtml(ModelMap map){
        map.addAttribute("msg","testhtml");
        System.out.println("msg testhtml");
        List<GgUser> user = userRepository.findAll();
        System.out.println(user.size());
        map.addAttribute("user",user);
        return "login";
    }

    @RequestMapping(value = "userlist")
    public String userlist(@RequestParam(value = "name", required = false, defaultValue = "world")
                                   String name, Map<String,Object> map){

        map.put("msg","from TestController.userlist");
        return "index";
    }
}
